# This scipt can change a block in a file.
import my_function as my
import re
# block_head is a word without = and {

game_path = '/home/h/games/v3'
region_path = '/game/map_data/state_regions/00_west_europe.txt'
building_groups_path = '/game/common/building_groups/00_building_groups.txt'
buildings_path = '/game/common/buildings'
error_gui_path = '/game/gui/error_deer.gui'
# resources
block_head = "capped_resources"
file_path = game_path + region_path
new_block_content = ''
my.replace_block(file_path, block_head, new_block_content)

block_head = "resource"
# file_path = "/home/h/games/Victoria 3/game/map_data/state_regions/12_indonesia.txt"
new_block_content = ''
my.replace_block(file_path, block_head, new_block_content)

block_head = "arable_resources"
# file_path = "/home/h/games/Victoria 3/game/map_data/state_regions/12_indonesia.txt"
new_block_content = ''
my.replace_block(file_path, block_head, new_block_content)

# building_groups
file_path = game_path + building_groups_path
with open(file_path, 'r', encoding='utf-8') as file:
    content = file.read()
content = re.sub('land_usage = rural', 'always_possible = yes', content)
content = re.sub('capped_by_resources = yes', 'always_possible = yes', content)
with open(file_path, 'w', encoding='utf-8') as file:
    file.write(content)

# buildings
block_head = "building_gold_mine"
file_path = game_path + buildings_path + '/03_mines.txt'
my.replace_block_no_reg(file_path, block_head, '')

block_heads = ['building_rye_farm', 'building_wheat_farm', 'building_maize_farm', 'building_millet_farm', 'building_vineyard_plantation']
for block_head in block_heads:
    file_path = game_path + buildings_path + "/02_agro.txt"
    my.replace_block_no_reg(file_path, block_head, '')

block_heads = ['building_coffee_plantation', 'building_tobacco_plantation', 'building_banana_plantation', 'building_vineyard_plantation']
for block_head in block_heads:
    file_path = game_path + buildings_path + "/04_plantations.txt"
    my.replace_block_no_reg(file_path, block_head, '')

# gui
block_heads = ['flowcontainer']
for block_head in block_heads:
    file_path = game_path + error_gui_path
    my.replace_block_no_reg(file_path, block_head, '')